﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Modulos/ModuloPrestamo/VistaControl/MasterPagePrestamo.master" AutoEventWireup="true" CodeFile="confirmaPrestamos.aspx.cs" Inherits="Modulos_ModuloPrestamo_VistaControl_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
Módulo de Préstamos - Confirmación de préstamos
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h2>Confirmar devolución de préstamo</h2><br />
Seleccione la carta a confirmar:
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="CARTA_ID" DataSourceID="SqlDataSource1" 
        EmptyDataText="No hay registros de datos para mostrar." AllowPaging="True" 
        AllowSorting="True" onselectedindexchanged="cambiaLabel">
        <Columns>
            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                        OnClientClick="javascript:if(!confirm('&iquest;Confirma actualizar carta?'))return false" 
                        CommandName="Update" Text="Actualizar"></asp:LinkButton>
                    <br /><asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text="Cancelar"></asp:LinkButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Select" Text="Seleccionar"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="CARTA_ID" HeaderText="Id" ReadOnly="True" 
                SortExpression="CARTA_ID" />
            <asp:TemplateField HeaderText="Usuario" SortExpression="USR_RUT">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="SqlDataSourceUsr1" DataTextField="USR_RUT"
                        SelectedValue='<%# Bind("USR_RUT") %>'
                        DataValueField="USR_RUT">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSourceUsr1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
                        SelectCommand="SELECT [USR_RUT] FROM [USUARIO]">
                    </asp:SqlDataSource>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("USR_RUT") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Lug. Entrega" SortExpression="LUG_ID">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" 
                        DataSourceID="SqlDataSourceLEntrega" DataTextField="NOMBRE_LUG" 
                        SelectedValue='<%# Bind("LUG_ID") %>'
                        DataValueField="LUG_ID">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSourceLEntrega" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
                        SelectCommand="SELECT [NOMBRE_LUG], [LUG_ID] FROM [LUGAR_ENTREGA_DEVOLUCION]">
                    </asp:SqlDataSource>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownListasd" runat="server" 
                        DataSourceID="SqlDataSourceLEntregagyu" DataTextField="NOMBRE_LUG" 
                        SelectedValue='<%# Bind("LUG_ID") %>'
                        Enabled="false"
                        DataValueField="LUG_ID">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSourceLEntregagyu" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
                        SelectCommand="SELECT [NOMBRE_LUG], [LUG_ID] FROM [LUGAR_ENTREGA_DEVOLUCION]">
                    </asp:SqlDataSource>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Lug. Dev." SortExpression="LUG_LUG_ID">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownListDEV" runat="server" 
                        DataSourceID="SqlDataSourceLDev" DataTextField="NOMBRE_LUG" 
                        SelectedValue='<%# Bind("LUG_LUG_ID") %>'
                        DataValueField="LUG_ID">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSourceLDev" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
                        SelectCommand="SELECT [NOMBRE_LUG], [LUG_ID] FROM [LUGAR_ENTREGA_DEVOLUCION]">
                    </asp:SqlDataSource>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownListDEV1" runat="server" 
                        DataSourceID="SqlDataSourceLDev1" DataTextField="NOMBRE_LUG" 
                        SelectedValue='<%# Bind("LUG_LUG_ID") %>'
                        Enabled="false"
                        DataValueField="LUG_ID">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSourceLDev1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
                        SelectCommand="SELECT [NOMBRE_LUG], [LUG_ID] FROM [LUGAR_ENTREGA_DEVOLUCION]">
                    </asp:SqlDataSource>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Beneficiario" SortExpression="RUT_BEN">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList3" runat="server" 
                        DataSourceID="SqlDataSourcebene" DataTextField="RUT_BEN" 
                        SelectedValue='<%# Bind("RUT_BEN") %>'
                        DataValueField="RUT_BEN">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSourcebene" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
                        SelectCommand="SELECT [RUT_BEN] FROM [BENEFICIARIO]"></asp:SqlDataSource>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("RUT_BEN") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Fecha inicio" SortExpression="FECHA_INI_CARTA">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("FECHA_INI_CARTA") %>'></asp:TextBox>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                        ControlToValidate="TextBox5" Display="Dynamic" 
                        ErrorMessage="* formato: 01/01/01 00:00:00" 
                        ValidationExpression="\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}"></asp:RegularExpressionValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("FECHA_INI_CARTA") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Fecha fin" SortExpression="FECHA_FIN_CARTA">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("FECHA_FIN_CARTA") %>'></asp:TextBox>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" 
                        ControlToValidate="TextBox6" Display="Dynamic" 
                        ErrorMessage="* formato: 01/01/01 00:00:00" 
                        ValidationExpression="\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}"></asp:RegularExpressionValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label6" runat="server" Text='<%# Bind("FECHA_FIN_CARTA") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Comentario" SortExpression="COMENTARIO_CARTA">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox7" runat="server" 
                        Text='<%# Bind("COMENTARIO_CARTA") %>' TextMode="MultiLine"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label7" runat="server" Text='<%# Bind("COMENTARIO_CARTA") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
        DeleteCommand="DELETE FROM [CARTA_PRESTAMO] WHERE [CARTA_ID] = @CARTA_ID" 
        InsertCommand="INSERT INTO [CARTA_PRESTAMO] ([USR_RUT], [LUG_ID], [USU_USR_RUT], [LUG_LUG_ID], [RUT_BEN], [FECHA_INI_CARTA], [FECHA_FIN_CARTA], [COMENTARIO_CARTA]) VALUES (@USR_RUT, @LUG_ID, @USU_USR_RUT, @LUG_LUG_ID, @RUT_BEN, @FECHA_INI_CARTA, @FECHA_FIN_CARTA, @COMENTARIO_CARTA)" 
        ProviderName="<%$ ConnectionStrings:AppCeiiConnectionString.ProviderName %>" 
        SelectCommand="SELECT [CARTA_ID], [USR_RUT], [LUG_ID], [USU_USR_RUT], [LUG_LUG_ID], [RUT_BEN], [FECHA_INI_CARTA], [FECHA_FIN_CARTA], [COMENTARIO_CARTA] FROM [CARTA_PRESTAMO] WHERE ([USU_USR_RUT] &lt;&gt; @USU_USR_RUT)" 
        
        UpdateCommand="UPDATE [CARTA_PRESTAMO] SET [USR_RUT] = @USR_RUT, [LUG_ID] = @LUG_ID, [USU_USR_RUT] = @USU_USR_RUT, [LUG_LUG_ID] = @LUG_LUG_ID, [RUT_BEN] = @RUT_BEN, [FECHA_INI_CARTA] = @FECHA_INI_CARTA, [FECHA_FIN_CARTA] = @FECHA_FIN_CARTA, [COMENTARIO_CARTA] = @COMENTARIO_CARTA WHERE [CARTA_ID] = @CARTA_ID">
        <SelectParameters>
            <asp:Parameter DefaultValue="0" Name="USU_USR_RUT" Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="CARTA_ID" Type="Decimal" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="USR_RUT" Type="Int32" />
            <asp:Parameter Name="LUG_ID" Type="Decimal" />
            <asp:Parameter Name="USU_USR_RUT" Type="Int32" />
            <asp:Parameter Name="LUG_LUG_ID" Type="Decimal" />
            <asp:Parameter Name="RUT_BEN" Type="Int32" />
            <asp:Parameter Name="FECHA_INI_CARTA" Type="DateTime" />
            <asp:Parameter Name="FECHA_FIN_CARTA" Type="DateTime" />
            <asp:Parameter Name="COMENTARIO_CARTA" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="USR_RUT" Type="Int32" />
            <asp:Parameter Name="LUG_ID" Type="Decimal" />
            <asp:Parameter Name="USU_USR_RUT" Type="Int32" />
            <asp:Parameter Name="LUG_LUG_ID" Type="Decimal" />
            <asp:Parameter Name="RUT_BEN" Type="Int32" />
            <asp:Parameter Name="FECHA_INI_CARTA" Type="DateTime" />
            <asp:Parameter Name="FECHA_FIN_CARTA" Type="DateTime" />
            <asp:Parameter Name="COMENTARIO_CARTA" Type="String" />
            <asp:Parameter Name="CARTA_ID" Type="Decimal" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <br />
    Carta N&ordm;<asp:Label ID="LabelNoCarta" runat="server" Text="(Seleccione una carta)"></asp:Label><br />
    <asp:Button ID="ButtonConfirmar" runat="server" Text="Confirmar" 
        Enabled="False" onclick="ButtonConfirmar_Click" 
        OnClientClick="javascript:if(!confirm('La acción de confirmación sobre el evento de devoloción del préstamo no puede revertirse, &iquest;Desea continuar?'))return false"
        ToolTip="La confirmación es realizada por el usuario actual del sistema" />
</asp:Content>

